3.3 Button Groups

It is handy for the user when buttons are linked in groups in accordance with their functions. The butgrp is a tabstop object - it is derived from the tabstop class. Therefore you can move from one button group to another striking TAB key on the keyboard or Shift-TAB if you want to move in reverse order. The button group concept makes a crowd of buttons more organized and the access to the individual button easier.

Constructor:

butgrp (
int x0, int y0, // the starting point
int xlen, int ylen, // size of buttons
int direction = HORIZ, // The direction of button's lining up
// May be VERT or HORIZ.
int distance = 0 ); // Gap between buttons. In VGA pixels.

The xlen, ylen are horizontal and vertical sizes of buttons in that group. The x0, y0 is the starting point - defines the upper left corner of the first button of button group on the screen.

By default buttons in group visually are lined up in the horizontal direction. If you want to organize them vertically pass VERT constant for direction parameter. Distance between buttons is zero by default. This is the most economical use of the space on the screen.


Data members:

None accessible to the user. There are two private static data members x0 and y0 which define the location of the next button in the group. When you declare a button, its constructor increases these variables in accordance with xlen or ylen and direction and distance parameters of butgrp costructor.

Methods:

virtual void Paint(void);

Paints all buttons of the group on the screen. In effect this method calls subsequently individual Paint() method of each button.

Shifts. Allow you to customize disposition of buttons on the screen. By default buttons are simply lining up horizontally or vertically. The Shift methods modify private static data members x0 and y0, changing position of the button to be declared next:

void ShiftX( int x);
void ShiftY( int y);

Add x to x0 and y to y0

void ShiftToX( int x);
void ShiftToY( int y);

Make x0 = x and y0 = y.

To switch between button groups use butsystem method NextTabStop()
and PrevTabStop().

Example 3.1.1:

#define butFONT         SMALL_FONT
#define butFONT_SIZE    4

butgrp bgCamacCtrl( CamacCtrl_but_x0, CamacCtrl_but_y0,
             /* size of button:*/ 60,18, VERT, 2 /* gap */ );

 button butEnterAC("AC", 'A','a', bpEnterAC, butFONT, butFONT_SIZE);
 button butEnterDC("DC", 'D','d', bpEnterDC, butFONT, butFONT_SIZE);
 indbutton ibutHeater("Heater", 'H','h', bpHeater,
                      4 /* radius of ind.*/,butFONT, butFONT_SIZE);
 button butGain("Gain", 'G','g', bpGain, butFONT, butFONT_SIZE);

butgrp bgHorizButtons( 3, maxy-25,      // starting point
                       70, 20);         // size of button
 button butQuit( "Quit", 'Q','q', bpQuit, 0,1, quittexcol, quitbutcol);
 button butHelp( "Help", 'H','h', bpHelp);
  bgHorizButtons.ShiftX(10);
 button but Tdependence( "Tdep", 0,67 /* F9 */, bpTdep);
 button butTdepGraph( "Graph", 'G','g', bpTdepGraph);

bgCamacCtrl.Paint();
bgHorizButtons.Paint();

Here are declared two button groups - bgCamacCtrl and bgHorizButtons. Camac control buttons are smaller and are lined up vertically with gaps between buttons equal to two VGA pixels. The texts on these buttons are smaller than on the buttons of bgHorizButtons group. All colors are default button colors except of the "Quit" button that is red with white text (these colors are also standard for Virtual Panels, see section 3.5). The peculiarity of bgCamacCtrl group is the ibutHeater button with LED indicator. The bpHeater switches heater on or off while indicator shows its state. In HorizButtons group we used ShiftX method to make a gap between general purpose buttons and buttons devoted to T- dependence measurement.

You can click button choosing it by arrow keys and pushing Enter, or striking the shortcut letter on the keyboard. Any two ASCII codes or one extended ASCII code may be used as a short-cuts. Usually it is preferable to define short-cuts as the upper-case and the lower-case letters emphasized (in a upper-case) on the title of the button. Another way is to put ascii0=0 and then ascii1 defines extended ASCII code. In this case you must be sure that the extended ASCII code doesn't clash with keys reserved by Virtual Panels (see Appendix B). In the example 3.1.1 T-dependence measurement is started off by pushing F9 key.

** Short-cut ASCII codes must be unique within the button group.

** Declaration of the button group makes it current. Buttons are linked to the current button group as they are declared in the run- time order, until a new button group is declared.